//
//  CTPWikiProxyFetcher.m
//  citipad
//
//  Created by Chih Yuan Liu on 2/19/11.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "CTPWikiProxyFetcher.h"
#import "NSString+URLEncoding.h"
#import "CTPWikiData.h"
#import "CTPWikiProxyParser.h"

@implementation CTPWikiProxyFetcher

- (void)requestSucceeded {
	NSString *responseString = [[NSString alloc] initWithData:recievedData encoding:NSUTF8StringEncoding];
	NSLog(@"%@", responseString);
	CTPWikiProxyParser* parser =[[CTPWikiProxyParser alloc] init];
	NSMutableArray * array = [parser parse:responseString]; 
	NSLog(@"%@",[array objectAtIndex:0]);
	[delegate wikiProxyFetcherSucceeded: self data:array];
	[delegate wikiProxyFetcherEnd:self];
}

-(void)requestFailed:(NSError*)error {
	[delegate wikiProxyFetcherFailed:self];
	[delegate wikiProxyFetcherEnd:self];
}

-(NSString*) URLForProxy:(NSString*) title{
	NSString* url = [NSString stringWithFormat:
					 //@"http://114.34.48.246/CtpSvr/svr.ashx?method=wiki&key=%@",
					 @"http://192.168.1.108/ctpsvr/CtpWikiProxy.ashx?key=上海市",
					 title];
	NSLog(@"%@", url);
	return url;
}

-(void)getDataFromProxy:(NSString*) title{
	NSString* url = [self URLForProxy:title];
	[super requestGET:url];
	[delegate wikiProxyFetcherBegin:self];
}

@synthesize delegate;

@end
